package day17_Inet.demo09_TCP;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server_TCL {
    public static void main(String[] args) throws Exception{
        ServerSocket ss = new ServerSocket(8888);
        Socket socket = ss.accept();
        while (true){
            //接收 发送过来的数据为abcdefg
            byte[] bytes = new byte[1024];
            InputStream is = socket.getInputStream();
            String s=null;
            int i;
            while ((i=is.read(bytes))!=-1){//该方法阻塞直到输入数据可用
                s = new String(bytes, 0, i);
            }
            if(s.equals("bye")){
                break;
            }
            //发送
            OutputStream os = socket.getOutputStream();
            os.write("abc".getBytes());
        }

        ss.close();


    }
}
